<template>
	<view>
		<view class="content-view">
			<view class="title util-font-regular">提现金额</view>
			<view class="input-view util-font-medium">
				<view class="price-icon">￥</view>
				<input class="price-input util-font-medium" type="digit" :value="value" focus="true" @input="priceInput" />
				<!-- <input  class="input" type="text" type="digit" value="" :placeholder="{'请输入提现金额(最高' + parseInt(data.amount)/100. +'元)'}" @input="input" /> -->
			</view>
			<view class="price-tips util-font-regular">最高可提现{{parseInt(amount)/100.}}元</view>
		</view>
		<view class="content-view">
			<view class="title util-font-regular">提现方式</view>
			<view class="type-row" style="margin-top: 20rpx;border-top: 2rpx solid #f1f1f1;"  @click="alipay">
				<image class="row-image" src="../../static/order/alipay.png" mode="aspectFit"></image>
				<view class="row-title util-font-regular">提现到支付宝</view>
				<image class="wechat-pay-select" src="../../static/order/select.png" mode="aspectFit"></image>
			</view>
			<view class="type-row" @click="wechat">
				<image class="row-image" src="../../static/order/wechat.png" mode="aspectFit"></image>
				<view class="row-title util-font-regular" style="color: #999999;">提现到微信（正在接入）</view>
				<image class="wechat-pay-select" src="../../static/order/unselect.png" mode="aspectFit"></image>
			</view>
		</view>
		<view v-if="selectIndex == 0" class="content-view util-font-regular">
			<view v-if="alipayAccount && alipayName" class="title">已绑定支付宝账号</view>
			<view v-else class="title">未绑定支付宝账号</view>
			<view v-if="alipayAccount && alipayName" class="text" style="margin-top: 20rpx;">账号：{{alipayAccount}}</view>
			<view v-if="alipayAccount&& alipayName" class="text">实名认证：{{alipayName}}</view>
			<view v-if="alipayAccount&& alipayName" class="alipay-button" @click="bindAliPay">更改账号</view>
			<view v-else class="alipay-button" @click="bindAliPay">去绑定</view>
		</view>
		<view class="confirm util-font-medium" @click="confirm">提    交</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				amount: '',
				value: '',
				selectIndex: 0,
				
				alipayAccount: null,
				alipayName: null,
				
			}
		},
		onShow() {
			this.loadData()
			this.loadAlipayInfo()
		},
		methods: {
			loadData: function(){
				var that = this
				that.sendRequest({
					url: 'app/appBrokerageRecords/withdrawStatistics/' + uni.getStorageSync('userInfo').id,
					method: 'POST',
					header: that.$urlRequest.getHeader('token'),
					success: function(res){
						that.amount = res.data.data.amount
					}
				})
			},
			loadAlipayInfo: function(){
				var that = this
				that.sendRequest({
					url: 'app/appUserAlipay/info/' + uni.getStorageSync('userInfo').id,
					method: 'POST',
					header: that.$urlRequest.getHeader('token'),
					success: function(res){
						that.alipayAccount = res.data.data.alipayAccount
						that.alipayName = res.data.data.alipayName
					}
				})
			},
			
			priceInput: function(event){
				this.value = event.detail.value
			},
			
			wechat: function(){
				uni.showModal({
					content: '提现到微信功能正在接入中，请耐心等待，如有问题，请联系客服',
					showCancel: false
				});
			},
			bindAliPay: function(){
				uni.navigateTo({
					url: 'bindAliPayInfo'
				})
			},
			confirm: function(){
				if (parseFloat(this.value)*100 > parseInt(this.amount)) {
					uni.showModal({
						content: '提现金额不得超过账户余额',
						showCancel: false
					});
					return
				}
				if (!parseFloat(this.value) || (parseFloat(this.value)*100 <= 0)){
					uni.showModal({
						content: '请输入正确的提现金额',
						showCancel: false
					});
					return
				}
				
				if (this.selectIndex == 0) {
					if (!(this.alipayAccount && this.alipayName)) {
						uni.showModal({
							content: '请前往绑定您的支付宝账号',
							showCancel: false
						});
						return
					}
				}
				
				
				var that = this
				that.sendRequest({
					url: 'app/appBrokerage/withdraw',
					method: 'POST',
					header: that.$urlRequest.getHeader('token'),
					data: {
						userId: uni.getStorageSync('userInfo').id,
						money: parseFloat(this.value)*100,
						type: 1
					},
					success: function(res){
						if (res.data.code == 0) {
							uni.showToast({
								title: '提现申请成功'
							})
							setTimeout(function(){
								uni.navigateBack({
									
								})
							}, 1000)
						}else{
							uni.showModal({
								content: '' + res.data.msg,
								showCancel: false
							});
						}
					}
				})
			}
		}
	}
</script>

<style>
	page {
		background-color: #F5F5F5;
	}
	.content-view {
		background-color: #FFFFFF;
		width: 650rpx;
		margin: 20rpx;
		padding: 30rpx;
		border-radius: 20rpx;
		position: relative;
	}
	.title {
		color: #333333;
		font-size: 28rpx;
	}
	.input-view {
		width: 650rpx;
		height: 100rpx;
		/* background-color: #f1f1f1; */
		border-bottom: 2rpx solid #F1F1F1;
	}
	.price-icon {
		width: 50rpx;
		height: 100rpx;
		line-height: 100rpx;
		float: left;
	}
	.price-input{
		width: 600rpx;
		height: 100rpx;
		line-height: 100rpx;
		font-size: 40rpx;
		color: #333333;
		float: right;
	}
	.placeholder-class {
		color: #999999;
		font-size: ;
	}
	.price-tips {
		height: 30rpx;
		line-height: 30rpx;
		font-size: 24rpx;
		color: #999999;
		margin-top: 20rpx;
	}
	.type-row {
		width: 650rpx;
		height: 88rpx;
		border-bottom: 2rpx solid #F1F1F1;
	}
	.row-image {
		width: 45rpx;
		height: 45rpx;
		margin-top: 22rpx;
		float: left;
	}
	.row-title {
		height: 88rpx;
		line-height: 88rpx;
		font-size: 30rpx;
		color: #333333;
		margin-left: 20rpx;
		float: left;
	}
	.wechat-pay-select {
		width: 40upx;
		height: 40upx;
		float: right;
		margin-top: 24upx;
	}
	.confirm {
		width: 650rpx;
		height: 80rpx;
		border-radius: 15rpx;
		line-height: 80rpx;
		text-align: center;
		font-size: 32rpx;
		background-color: #EB8735;
		margin-left: 50rpx;
		margin-top: 50rpx;
		color: #FFFFFF;
	}
	
	.text {
		color: #333333;
		font-size: 24rpx;
	}
	.alipay-button {
		position: absolute;
		top: 30rpx;
		right: 30rpx;
		color: #EB8735;
		font-size: 24rpx;
	}
</style>
